home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d985.lha / NewIFF / NewIFF39.lha / newiff39 / apps / ILBMtoC / ILBMtoC.c < prev    next >
C/C++ Source or Header  |  1993-09-28  |  4KB  |  165 lines

  1. /*--------------------------------------------------------------*/
  2. /*                                */
  3. /* ILBMtoC: reads in ILBM, prints out ascii representation,     */
  4. /*  for including in C files.                     */
  5. /*                                                              */
  6. /* Based on ILBMDump.c by Jerry Morrison and Steve Shaw,    */
  7. /* Electronic Arts.                               */
  8. /* Jan 31, 1986                            */
  9. /*                                                              */
  10. /* This software is in the public domain.                       */
  11. /* This version for the Commodore-Amiga computer.               */
  12. /*                                                              */
  13. /*  Callable from CLI ONLY                    */
  14. /*  modified 05-91 for use wuth iffparse modules        */
  15. /*  Requires linkage with several other modules - see Makefile  */
  16. /*--------------------------------------------------------------*/
  17. #define INTUI_V36_NAMES_ONLY
  18.  
  19. #include "iffp/ilbmapp.h"
  20.  
  21.  
  22. #ifdef __SASC
  23. void __chkabort(void) {}          /* Disable SAS CTRL-C checking. */
  24. #else
  25. #ifdef LATTICE
  26. void chkabort(void) {}            /* Disable LATTICE CTRL-C checking */
  27. #endif
  28. #endif
  29.  
  30.  
  31. #include "ilbmtoc_rev.h"
  32. UBYTE vers[] = VERSTAG;
  33. UBYTE Copyright[] = VERS " - Save ILBM as C source - Freely Redistributable";
  34.  
  35. void GetSuffix(UBYTE *to, UBYTE *fr);
  36. void bye(UBYTE *s, int e);
  37. void cleanup(void);
  38.  
  39. struct Library *IFFParseBase = NULL;
  40. struct Library *GfxBase = NULL;
  41.  
  42. /* ILBM frame */
  43. struct ILBMInfo ilbm = {0};
  44.  
  45.  
  46. /* ILBM Property chunks to be grabbed - only BMHD needed for this app
  47.  */
  48. LONG    ilbmprops[] = {
  49.         ID_ILBM, ID_BMHD,
  50.         TAG_DONE
  51.         };
  52.  
  53. /* ILBM Collection chunks (more than one in file) to be gathered */
  54. LONG    *ilbmcollects = NULL;    /* none needed for this app */
  55.  
  56. /* ILBM Chunk to stop on */
  57. LONG    ilbmstops[] = {
  58.         ID_ILBM, ID_BODY,
  59.         TAG_DONE
  60.         };
  61.  
  62.  
  63. UBYTE defSwitch[] = "b";
  64.  
  65. /** main() ******************************************************************/
  66.  
  67. void main(int argc, char **argv)
  68.     {
  69.     UBYTE *sw;
  70.     FILE *fp;
  71.     LONG error=NULL;
  72.     UBYTE *ilbmname, name[80], fname[80];
  73.  
  74.     if ((argc < 2)||(argv[argc-1][0]=='?'))
  75.     {
  76.     printf("Usage from CLI: 'ILBMtoC filename switch-string'\n");
  77.     printf(" where switch-string = \n");
  78.     printf("  <nothing> : Bob format (default)\n");
  79.     printf("  s         : Sprite format (with header and trailer words)\n");
  80.     printf("  sn        : Sprite format (No header and trailer words)\n");
  81.     printf("  a         : Attached sprite (with header and trailer)\n");
  82.     printf("  an        : Attached sprite (No header and trailer)\n");
  83.     printf(" Add 'c' to switch list to output CR's with LF's   \n");
  84.     exit(RETURN_OK);
  85.     }
  86.     
  87.  
  88.     if(!(GfxBase = OpenLibrary("graphics.library",0)))
  89.     bye("Can't open graphics.library",RETURN_FAIL);
  90.  
  91.     if(!(IFFParseBase = OpenLibrary("iffparse.library",0)))
  92.     bye("Can't open iffparse.library",RETURN_FAIL);
  93.  
  94. /*
  95.  * Here we set up default ILBMInfo fields for our
  96.  * application's frames.
  97.  * Above we have defined the propery and collection chunks
  98.  * we are interested in (some required like BMHD)
  99.  */
  100.     ilbm.ParseInfo.propchks      = ilbmprops;
  101.     ilbm.ParseInfo.collectchks   = ilbmcollects;
  102.     ilbm.ParseInfo.stopchks      = ilbmstops;
  103.     if(!(ilbm.ParseInfo.iff = AllocIFF()))
  104.         bye(IFFerr(IFFERR_NOMEM),RETURN_FAIL);    /* Alloc an IFFHandle */
  105.  
  106.     sw = (argc>2) ? (UBYTE *)argv[2] : defSwitch;
  107.     ilbmname = argv[1];
  108.  
  109.     if (error = loadbrush(&ilbm,ilbmname))
  110.         {
  111.         printf("Can't load ilbm \"%s\", ifferr=%s\n",ilbmname,IFFerr(error));
  112.         bye("",RETURN_WARN);
  113.         }
  114.     else /* Successfully loaded ILBM */
  115.     {
  116.     printf(" Creating file %s.c \n",argv[1]);
  117.     GetSuffix(name,argv[1]);
  118.     strcpy(fname,argv[1]);
  119.     strcat(fname,".c");
  120.     fp = fopen(fname,"w");
  121.     if(fp)
  122.         {
  123.         BMPrintCRep(ilbm.brbitmap,fp,name,sw);
  124.         fclose(fp);
  125.         }
  126.     else  printf("Couldn't open output file: %s. \n", fname);
  127.     unloadbrush(&ilbm);
  128.     }
  129.     printf("\n");
  130.     bye("",RETURN_OK);
  131.     }
  132.  
  133.  
  134.  
  135. /* this copies part of string after the last '/' or ':' */
  136. void GetSuffix(to, fr) UBYTE *to, *fr; {
  137.     int i;
  138.     UBYTE c,*s = fr;
  139.     for (i=0; ;i++) {
  140.     c = *s++;
  141.     if (c == 0) break;
  142.     if (c == '/') fr = s;
  143.     else if (c == ':') fr = s;
  144.     }
  145.     strcpy(to,fr);
  146.     }
  147.  
  148.  
  149. void bye(UBYTE *s, int e)
  150.     {
  151.     if(s&&(*s))    printf("%s\n",s);
  152.     cleanup();
  153.     exit(e);
  154.     }
  155.  
  156.  
  157. void cleanup()
  158.     {
  159.     if(ilbm.ParseInfo.iff)        FreeIFF(ilbm.ParseInfo.iff);
  160.  
  161.     if(IFFParseBase)    CloseLibrary(IFFParseBase);
  162.     if(GfxBase)        CloseLibrary(GfxBase);
  163.     }
  164.  
  165.